// src/store/modules/mocking.ts
import { reqGetMockingList } from "@/api/index";
import { Module } from "vuex";
import { MockingData, MockingResponse, MockingState } from "@/types/mockTypes";

const state: MockingState = {
  mockingList: [], // mock数据
};

const mutations = {
  GETMOCKINGLIST(state: MockingState, mockingList: MockingData[]) {
    state.mockingList = mockingList;
  },
};

const actions = {
  async getMockingList({
    commit,
  }: {
    commit: (type: string, payload?: MockingData[]) => void;
  }) {
    console.log("运行：reqGetMockingList");
    const res: MockingResponse = await reqGetMockingList(); // 调用 API 请求
    if (res.code === 200) {
      commit("GETMOCKINGLIST", res.data); // 提交数据到 mutations
    }
  },
};

const getters = {
  // 可选：添加一些 getters 以便方便获取 mock 数据
  getMockingList(state: MockingState) {
    console.log("store/modules/mocking.ts::getMockingList");
    return state.mockingList;
  },
};

// eslint-disable-next-line
const mockingModule: Module<MockingState, any> = {
  state,
  mutations,
  actions,
  getters,
};

export default mockingModule;
